package com.cjh.utils;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 生产者配置类-routing-topic
 */
@Configuration
public class RoutingTopicConfig {
    /**
     * 声明交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        TopicExchange topicExchange = new TopicExchange("topics");
        return topicExchange;
    }

    /**
     * 声明队列 1 绑定 info 和 warm
     */
    @Bean
    public Queue topicQueue1() {
        return new Queue("topicQueue1");
    }

    /**
     * 声明队列 2
     */
    @Bean
    public Queue topicQueue2() {
        return new Queue("topicQueue2");
    }

    /**
     * 把队列 1 绑定到交换机里面指定 user.*的路由 key
     */
    @Bean
    public Binding binding111() {
        Binding binding = BindingBuilder.bind(topicQueue1())
                .to(topicExchange()).with("user.*");
        return binding;
    }

    /**
     * 把队列 2 绑定到交换机里面指定 user.#的路由 key
     */
    @Bean
    public Binding binding222() {
        Binding binding = BindingBuilder.bind(topicQueue2())
                .to(topicExchange()).with("user.#");
        return binding;
    }
}